Option Strict Off
Option Explicit On

Imports System.Runtime.InteropServices

Friend Class frmCapture
    Inherits System.Windows.Forms.Form 'Declares that all variables must be defined before use.


    Public Delegate Function WindowProcDelegate(ByVal hwnd As Integer, ByVal msg As Integer, ByVal wParam As Integer, ByRef lParam As WINDOWPOS) As Integer    

    <MarshalAs(UnmanagedType.FunctionPtr)> Private callback As WindowProcDelegate



    Private Sub frmCapture_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
        'UPGRADE_WARNING: Add a delegate for AddressOf NewWindowProc Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="E9E157F7-EF0C-4016-87B7-7D7FBBC6EE08"'

        callback = New WindowProcDelegate(AddressOf NewWindowProc)

        'OldWindowProc = SetWindowLong(Handle.ToInt32, GWL_WNDPROC, AddressOf NewWindowProc) 'Fix aspect ratio
        OldWindowProc = SetWindowLong(Handle.ToInt32, GWL_WNDPROC, callback) 'Fix aspect ratio
        'TODO - This code is completely not working - have to figure out the whole delegate thing
        DisableCloseWindowButton(Me)
    End Sub

    Private Sub frmCapture_FormClosing(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Dim Cancel As Boolean = eventArgs.Cancel
        Dim UnloadMode As System.Windows.Forms.CloseReason = eventArgs.CloseReason
        If UnloadMode = System.Windows.Forms.CloseReason.UserClosing Then
            Cancel = True 'Prevent the window from being closed by the 'X' Button
        End If
        eventArgs.Cancel = Cancel
    End Sub

    Public Sub frmCaptureResize()
        'Check if the capture window has been resized. if so, adjust the image in the window to the correct size
        If (VB6.PixelsToTwipsX(Me.Width) / VB6.TwipsPerPixelX) <> Me.picLive.Width Then
            Me.picLive.Width = (VB6.PixelsToTwipsX(Me.Width) / VB6.TwipsPerPixelX)
            Me.picLive.Height = Me.picLive.Width / AspRatio
            Me.picLive.Top = 0
            Me.picLive.Left = 0
            Me.picPlayBack.Width = (VB6.PixelsToTwipsX(Me.Width) / VB6.TwipsPerPixelX)
            Me.picPlayBack.Height = Me.picLive.Width / AspRatio
            Me.picPlayBack.Top = 0
            Me.picPlayBack.Left = 0
            If WindowAtFront = "PlayBack" Then
                PlayBackVideoWindow.Width = (VB6.PixelsToTwipsX(Me.Width) / VB6.TwipsPerPixelX)
                PlayBackVideoWindow.Height = Me.picLive.Width / AspRatio
            End If
        End If
    End Sub
End Class